package net.minecraft.src;

public class LF_ItemSpawner extends Item
{
	public LF_ItemSpawner(int i)
	{
		super(i);
	}

	@Override
	public boolean onItemUse(ItemStack itemstack, EntityPlayer entityplayer, World world, int i, int j, int k, int l)
	{
		int i1 = world.getBlockId(i, j, k);
		if(i1 == Block.snow.blockID)
			l = 0;
		else if(i1 != Block.vine.blockID)
		{
			if(l == 0)
				j--;
			if(l == 1)
				j++;
			if(l == 2)
				k--;
			if(l == 3)
				k++;
			if(l == 4)
				i--;
			if(l == 5)
				i++;
		}

		if(itemstack.stackSize == 0)
			return false;

		if(world.canBlockBePlacedAt(Block.pumpkin.blockID, i, j, k, false, l))
		{
			itemstack.stackSize--;
			LF_EntitySeat seat = new LF_EntitySeat(world, i, j, k);
			seat.setRotation(entityplayer.rotationYaw + 180, 0);

			if(snapRotation)
			{
				double snapRotation = Math.floor((seat.rotationYaw/90F) + 0.5F);
				seat.setRotation((int)snapRotation*90, 0);
			}

			world.spawnEntityInWorld(seat);

			return true;
		}
		else
			return false;
	}

	boolean snapRotation = true;
}
